const Service = require('egg').Service;
const fs = require('fs');
class photoService extends Service {
    listAllPhotos() {
        let {
            path,
            urlSuffix
        } = this.config.photo;
        path = path.trim('')
        const photoList = fs.readdirSync(path)
        let imgObjList = []
        photoList.forEach((filename) => {
            let res = fs.statSync(path+'/'+filename)
            imgObjList.push({
                url: `${urlSuffix}${filename}`,
                size: Math.floor(res.size / 1024),
                uploadTime: res.birthtime,
                filename
            })
        })
        return imgObjList;
    }
}
module.exports = photoService;